package FactoryMethod;

import FactoryMethod.Factory.IFactory;
import FactoryMethod.Factory.RebateThenReturnFactory;
import FactoryMethod.cashier.*;
import FactoryMethod.constants.CasherEnum;

/**
 * @author duanzhizhou
 * @date 2024/9/25
 */
public class CashContext {
    
    private final Cashier cashier;
    
    public CashContext(CasherEnum casherEnum) {
        IFactory factory = null;
        switch (casherEnum) {
            case HALF:
                factory = new RebateThenReturnFactory(0.5, 0, 0);
                break;
            case NORMAL:
                factory = new RebateThenReturnFactory(1, 0, 0);
                break;
            case QUARTER:
                factory = new RebateThenReturnFactory(0.25, 0, 0);
                break;
            case REBATE_THEN_RETURN:
                factory = new RebateThenReturnFactory(0.8, 300, 100);
                break;
            default:
                throw new RuntimeException("不支持的类型");
        }
        cashier = factory.create();
    }
    
    public double getMoney(double price, int num) {
        return cashier.check(price, num);
    }
    
}
